package com.genntii.examManager.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.genntii.examManager.domain.entity.ExamRecord;
import com.genntii.examManager.domain.entity.PracticeRecord;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;

@Mapper
public interface PracticeRecordMapper extends BaseMapper<PracticeRecord> {

    @Select("select * " +
            "from practice_record " +
            "where user_id = #{userId} " +
            "order by commit_time DESC " +
            "limit #{pageNum}, #{pageSize}")
    ArrayList<PracticeRecord> getPracticeHistory(@Param("userId") Long userId,
                                         @Param("pageNum") Integer pageNum,
                                         @Param("pageSize") Integer pageSize);

    @Select("select count(*) from practice_record where user_id = #{userId}")
    long getPracticeHistoryTotal(@Param("userId") Long userId);

    @Select("select count(*) from practice_record where user_id = #{userId} and status = 1 or status = 2")
    Integer getPracticeCountUserCompleted(@Param("userId")Long userId);

    @Select("select * from practice_record where user_id = #{userId} and practice_id = #{practiceId}")
    PracticeRecord selectByUserPractice(@Param("userId") Long userId,@Param("practiceId") Long practiceId);

    void insertBatchAll(ArrayList<PracticeRecord> practiceRecords);

    void insertBatch(Long id, ArrayList<Long> userIds);
    @Delete("delete from exam_manager.practice_record where exam_manager.practice_record.user_id = #{userId}")
    void deleteByUserIdAndPracticeIds(Long userId, ArrayList<Long> practiceIds);
}
